<template>
  <a-form-model
    class="form"
    :model="form"
    :label-col="labelCol"
    :wrapper-col="wrapperCol"
  >
    <a-form-model-item label="通知标题" required>
      <a-input v-model="form.name" />
    </a-form-model-item>
    <a-form-model-item label="发布时间">
      <a-date-picker show-time v-model="form.date1" style="width: 100%" />
    </a-form-model-item>
    <a-form-model-item label="发布单位" required>
      <a-input v-model="form.name" />
    </a-form-model-item>
    <a-form-model-item label="征集日期" required>
      <a-range-picker />
    </a-form-model-item>
    <a-form-model-item label="发布范围" required>
      <a-checkbox-group
        v-model="form.type"
        name="checkboxgroup"
        :options="plainOptions"
      />
    </a-form-model-item>
    <a-form-model-item label="通知内容" required>
      <a-input v-model="form.desc" type="textarea" />
    </a-form-model-item>
    <a-form-model-item label="附件">
      <a-upload
        action="https://www.mocky.io/v2/5cc8019d300000980a055e76"
        :multiple="true"
        :file-list="fileList"
        @change="handleChange"
      >
        <a-button> <a-icon type="upload" /> Upload </a-button>
      </a-upload>
    </a-form-model-item>
    <a-form-model-item label="备注信息">
      <a-input v-model="form.desc" type="textarea" />
    </a-form-model-item>
    <a-form-model-item label="短信提醒">
      <a-switch v-model="form.delivery" />
    </a-form-model-item>
    <a-form-model-item v-show="form.delivery" label="短信内容" required>
      <a-input v-model="form.desc" type="textarea" />
    </a-form-model-item>
    <div>
      <a-button type="primary" @click="onSubmit"> Create </a-button>
      <a-button style="margin-left: 10px" @click="$router.back()">
        Cancel
      </a-button>
    </div>
  </a-form-model>
</template>
<script>
export default {
  data() {
    return {
      labelCol: { span: 4 },
      wrapperCol: { span: 14 },
      plainOptions: [
        { label: 'Apple', value: 'Apple' },
        { label: 'Pear', value: 'Pear' },
        { label: 'Orange', value: 'Orange' }
      ],
      form: {
        name: '',
        region: undefined,
        date1: undefined,
        delivery: false,
        type: [],
        resource: '',
        desc: ''
      },
      fileList: [
        {
          uid: '-1',
          name: 'xxx.png',
          status: 'done',
          url: 'http://www.baidu.com/xxx.png'
        }
      ]
    }
  },
  methods: {
    onSubmit() {
      console.log('submit!', this.form)
    },
    handleChange(info) {
      let fileList = [...info.fileList]

      // 1. Limit the number of uploaded files
      //    Only to show two recent uploaded files, and old ones will be replaced by the new
      fileList = fileList.slice(-2)

      // 2. read from response and show file link
      fileList = fileList.map((file) => {
        if (file.response) {
          // Component will show file.url as link
          file.url = file.response.url
        }
        return file
      })

      this.fileList = fileList
    }
  }
}
</script>